Optimal control of nanomechanical quantum memory coupled to superconducting qubit