I'd also thought of this independently in the past, presumably lots of people have. As for decelerating, I have no idea if any modern trains do this, but you could in theory charge a battery with the kinetic energy from decelerating the train and use that for acceleration. Naturally it wouldn't be a perfect energy transfer, but I presume much of it could be captured.