Going by train from Tallinn to Vilnius or v.v. is a challenge. It should work the following way: Tallinn ↔ Tartu ↔ Valga ↔ Riga ↔ Daugavpils ↔ Vilnius. I will explain it for the way from Vilnius to Tallinn: From Vilnius take the evening train to Daugavpils in Latvia (see Lithuanian Railways for timetable), this is the night train from Kaliningrad to St. Petersburg. Stay a night in Daugavpils and take the next day the local train to Riga (see Latvian Railway). From Riga take the local train to the border-town Valka/Valga. From Valga take the train via Tartu to Tallinn, you might have to change trains in Tartu (see Estonian Passenger Railway). That's how it theoretical works, but I havn't tried it, yet. If you made it, please email me. Thank you.
It's not so much known that flyLAL and AirBaltic both offer flights between Tallinn and Vilnius. Thanks to the competition prices get sometimes as cheap as the bus tickets. AirBaltic also offers flights from Riga to Tallinn and Vilnius.