The quantization of a single-mode EM field results in a Hamiltonian of a harmonic oscillator, given by $H=\hbar \omega (a^\dagger a + \frac{1}{2})$, where $a^\dagger a$ can be understood as the "photon number" operator. Therefore, each photon has an energy of $\hbar \omega$. The result stems directly from the formulation of the Maxwell equations, where your propagating field can be represented by plane waves of a given frequency, which is also emphasized by the fact that we are calling that field a single-mode field.
By a single-mode field we understand a solution, that represents only a single frequency of light manifested in the temporal dependency of our solution. The spatial part does not matter when obtaining the energy formula. In the case of a harmonic oscillator that models our field the $\exp(i\omega t)$ (or a sine wave) is a natural choice for a frequency basis (discussed here: Why do we hear frequencies in the basis of sine waves?).