Synthesis of neuronal network dynamics for optimal stimulus encoding and retention