An optimization technique determining the configuration of optical components in a spatial light modulator is proposed. We study a spatial light modulator composed of a twisted nematic liquid crystal, a polarization state generator, and a polarization state detector. To obtain the desired phase and amplitude modulations, four parameters of the polarization state generator and detector should be optimized. A genetic algorithm is applied in searching the configurations suitable to a given twisted nematic liquid crystal. By embodying the proposed technique, the evolution of the designed cost functions is proved.