I find that booking for the fast trains between one and three months before traveling generally works out the cheapest. If you are booking a regional train, the prices are generally the same regardless of when you book. A good idea is to download the Trenitalia app so that you can buy tickets online, and then the ticket inspector simply scans the QR code on your phone.