Can/should we buy tickets online?
Yes and Yes
How far in advance are tickets available online?
Recently I tried buying tickets from Kosice to Budapest about 2 months in advance and the sale wouldn't go through, so I waited a week and all was good; so yes, there might be some restrictions about how far in advance buy under 60 days I suspect no problem.
Are there sites you recommend? Sites to avoid?
Here is the Hungarian Rail Service (MAV) website: https://jegy.mav.hu/ Its been improved a bit this past year and is pretty easy to use. Avoid all other sites if you are departing Budapest.
I am not a romantic train traveler. Even the 3+ hour trip back to Budapest from Kosice is not one I am looking forward to (but worth it for the fishing). No way I would take the train to Prague; too many cheap and quicker flights. https://community.ricksteves.com/travel-forum/czech/prague-to-budapest-transportation-options But it is very much a personal preference thing and if you enjoy the trains then have a blast.