The answer depends on what the symbol $m$ represents.

If $m$ is the (non-zero) invariant mass of a particle, then $E=mc^2$ holds in an inertial reference frame (IRF) in which the particle is at rest.  If the particle has speed $v$ in an IRF, then the expression for the energy is

$$E = \gamma mc^2 = \frac{mc^2}{\sqrt{1 - \frac{v^2}{c^2}}}$$

and this equation is consistent with the energy-momentum equation written as

$$E^2 = (pc)^2 + (mc^2)^2$$

However, and confusingly, it is sometimes the case that $m$ represents the *relativistic* mass $\gamma m_0$ where $m_0$ is the (more or less outdated) *rest* mass thus 

$$E = mc^2 = \gamma m_0c^2 = \frac{m_0c^2}{\sqrt{1 - \frac{v^2}{c^2}}}$$

and then the energy-momentum equation is written as

$$E^2 = (pc)^2 + (m_0c^2)^2$$