Can railway system work in a country without a constant energy power supply?
Yes. The engines would have to run off fossil fuels if
electricity is intermittent (This is still the standard, anyways)
and a communications system based around local power sources would
have to be used. It would be the job of the railway company to keep
its stations powered (i.e. fueled). If the railway company can
control power to its infastructure, it can run successfully.