Most electric trains only have a small service-and-emergency battery and don't have significant energy storage. For AC electric locomotives it's now standard to return electricity to the grid when using regenerative braking; that's harder with DC electric traction but is done in some circumstances (in others, the generated electricity is dumped into heat via a resistor bank).
The main barrier to electrification is the high upfront capital cost of the electrification works, set against the longer-term per-train return in lower fuel and locomotive/multiple unit costs. Lines which are not intensively used are difficult to justify electrifying on a financial-returns basis, and that probably includes most of the world's long-distance freight lines.