I've had an interesting session with Chatgtp about this. The conclusion is that mainline trains would still have to run off the grid as they do now, because they would need far bigger batteries than would be feasible, but for shorter journeys it could work well, particularly if it used 'regenerative braking (don't ask..) and solar PV incorporated in the roofs of the engine and carriages to add some charge to the battery while the train is being operated, and the PV panels would be providing some charge all the time in daylight, Solar panels could be used at some stations to supplement the grid charge to a large stationery battery which could provide the charge needed to fully recharge the train battery.
It reckons that ideas like this are currently being developed.
It sounds good to me and does away with the expensive infrastructure of overhead wiring currently needed for electrification on routes that currently aren't electrified.