Unless you really like trains, you'll want to fly back from Chiang Mai instead. A flight+cheap hotel won't cost you much more than a sleeper, and you'll get a better night's sleep and extra time to sightsee.
Ayutthaya is doable in a day, although you didn't say what time of year you'll be there -- clambering around on the ruins in the midday sun in April will fry you to a crisp.