You can find all the information here:
http://seat61.com/Russia.htm
http://seat61.com/Finland.htm#Helsinki%20-%20St%20Petersburg%20by%20train
I personally recommend flying with Ryanair to Riga and then taking the train to either Moscow or St. Petersburg. These 2 trains are sleeper trains, so instead of sitting in the train wasting a travelling day you can sleep and save money on accomodation.
Normally taking the train is as easy as taking the bus or the ferry (buy the ticket and hop on), but (unlike in other European countries) Russian trains require reservation. Russian train tickets are made of 2 parts, one is the ticket and one is the reservation. Make sure you got both tickets and reservation. The reservation can be difficult to get outside of Russia, carefully follow the instructions on the website above.
Note that you need a visa to travel to Russia.
Expect it to be cool and rainy in May in St. Petersburg. That far north it is a lot colder than Canary Islands.