Pair creation
You are right: In free space a photon cannot
decay into an electron-positron pair
(because it would violate energy/momentum conservation).
However, near an atomic nucleus a photon can decay
into an electron-positron pair.
In this process the atomic nucleus receives some recoil.
See also Wikipedia: Pair production.
The process can be visualized by a Feynman diagram like below.

image from Wikipedia: Pair production
Pair annihilation
You are also right, that an electron-positron pair in free space cannot decay
into a photon (again because it would violate energy/momentum conservation).
However, an electron-positron pair can decay into
two photons. The two gamma ray photons depart
in roughly opposite directions.
See also Wikipedia: Electron–positron annihilation.
The process can be visualized by the Feynman diagram below.

image from Feynman diagram for annihilation