A single photon cannot spontaneously become an electron and a positron, as it would be unable to simultaneously conserve energy and momentum. For the same reason, an electron and a positron cannot annihilate into a single photon.
However, two colliding photons (if they have sufficient energy) can form and electron and a positron; and, an electron and positron can annihilate to form two photons.