Quantum state preparation and control of single molecular ions