Solution (source code)

= Solution

Both divergences vanish, so $\rho=0$. Faraday's and Ampere's curl equations respectively require
$$
kE_0=\omega B_0,
\qquad
kB_0=\omega E_0.
$$
For positive constants these imply
$$
\boxed{\omega=k,\qquad E_0=B_0,\qquad\rho=0}.
$$

The <Poynting vector> is
$$
P=E_0^2\widehat x\cos^2(kx-\omega t).
$$
Only the two $x$-faces of the box contribute to its outward flux. With $a=\pi/(2k)$,
$$
\begin{aligned}
\int_SP\cdot dS
&=L^2E_0^2[
\cos^2(ka-\omega t)-\cos^2(\omega t)]\\
&=-L^2E_0^2\cos(2\omega t).
\end{aligned}
$$
The electromagnetic energy inside the box is
$$
U(t)=L^2E_0^2\int_0^a\cos^2(kx-\omega t)\,dx,
$$
and direct differentiation, using $\omega=k$, gives
$$
\frac{dU}{dt}=L^2E_0^2\cos(2\omega t).
$$
Thus
$$
\boxed{\int_SP\cdot dS=-\frac{dU}{dt}},
$$
confirming the integral identity when $J=0$.