You have to go by train from Porto – Sao Bento.
Your final destination is Aveiro.
The website of comboios de portugal – CP.pt are very confusing and it’s very difficult find out something there. Here you have useful information:
Return: 5,10 Euro (if you are less than 25 years – not in the machine but you have to buy at the window)
Duration: 1:15 h
Timetable – schedule
You can find very cheap accommodation on Airbnb.com
On this portal are a lot offers for accommodation, if you use this registration promo code, you have 20 Euro discount for first use. – www.airbnb.cz/c/ondrav1
Another alternative is cheap hotel in Aveiro. (With this link you will have 10% discount.)