You don’t want to substitute $247$ for $E$: $E$ is the energy released by the earthquake, not the energy used by a household in a month. You want to use the Richter number to find $E$, then compute the total monthly energy consumption of $4.8$ million households, and finally see how many times that amount is released by the earthquake. I’ll get you started.
Substitute the Richter number $7.7$ for $M$ in your formula for the Richter number, and solve for $E$:
$$7.7=\frac23\log_{10}\frac{E}{0.007}\;,$$
so $$\log_{10}\frac{E}{0.007}=\frac32\cdot7.7=11.55\;.$$
Now exponentiate to get rid of the log:
$$\frac{E}{0.007}=10^{\log_{10}(E/0.007)}=10^{11.55}\;.$$
Multiply by $0.007$ to get $E$, the energy released in kWh:
$$E=0.007\cdot10^{11.55}\approx2.48\times10^9\text{ kWh}\;.$$