We present a theory of optical control of magnetism in a self-assembled quantum dot (SAD) containing magnetic ions. We show that the magnetic state of Mn ions can be controlled by the number of excitons in the dot. For an odd number of excitons the magnetic ions are coupled by the spins of valence holes and electrons. For an even number of excitons we derive the effective RKKY interaction between Mn ions, and show that it is controlled by valence holes. We predict the emission spectra of the coupled Mn-exciton system and relate them to the magnetic state of ions and the number of excitons in the quantum dot.