Who said you can't put batteries on a train? That would make more sense than putting them on a truck because you can haul way more tons of batteries and the friction of the steel wheels on a train is way less than tyres on asphalt.
It's really the same scenario as long haul trucking, except more so. Let's see: A relatively large diesel-electric locomotive has a fuel capacity of about 5000gal(us), or about 15,700kg. Even accounting for ~50% thermodynamic efficiency of the engine, it would take about 523 metric tons of lithium batteries to provide equivalent energy storage capacity. Even deducting about 20t for the diesel engine and generator, That makes about a 3.8x increase in the weight of 180t locomotive, and would require an additional 16 axles, before even accounting for the additional structural, mechanical, and electrical equipment required. The batteries would take up something like 12x the volume of the equivalent in diesel, but the limiting factor on size will probably be the 22+ axles you now need to fit under everything. The worst part, though, is that all of that extra weight comes out of the allowable trailing tonnage, which might be about 5000t for a locomotive of this class--so that's about a 10% performance penalty (again, only accounting for the weight of the batteries themselves). Sure, you could add additional traction motors to some of your new axles, but that trades pulling capacity for range, and further increases the weight and cost of the locomotive.
To top it off, locomotives probably can't take nearly as much advantage of regenerative braking as trucks can, because there's so much energy involved in slowing down a fully loaded train that the locomotive can only capture a small fraction of it, and they try not to do that very often anyway. Oh, and of course there's charging time to consider. At ~366GJ, it will take about four days to charge a battery of that size if you can do it at 1MW.