The tickets at discounted fare (Economy, Supereconomy, etc.) are now refundable (it was not the case in the past) but in order to be reimbursable you must have purchased the “TiRimborso” (I Reimburse you) option at the time you purchased the ticket. That option costs an additional €2 on top of the price of the ticket and is basically an insurance option. If you purchased it, you are entitled to the refund less 10%, in other words the refund is 90% of what you paid (which is still better than €0). However you must have purchased the “TiRimborso” option at the time of purchase of the ticket.
Regarding the tax code, that is called Codice Fiscale and you can generate it yourself since it’s based on your name, gender, birthdate, and province (or country) of birth. The number generated by various websites is not official but good enough for the purpose of proceeding on the Trenitalia website.
Here is one website.
https://zip-codes.nonsolocap.it/codice-fiscale/
Make sure your name matches your name in the passport. In the first name field make sure you include your middle name if you have one. If you were born in the US, enter it in Italian under place of birth (STATI UNITI D’AMERICA)