Quantum control of alignment and orientation of molecules by optimized laser pulses