This is a question that gets asked ad nauseum.
To say you are interested in onsens really doesn't help here, since onsens are available year round (yes, even in snowy areas you can find rotemburos open).
Best time of year is whatever time you want to enjoy it. So, what do you want to do here? Summer is very hot and humid in cities on Honshu. Winter on Hokkaido turns many away. What can you tolerate or not tolerate in the way of climate?
Some people want to see cherry blossoms or fall colors; I'd suggest Googling for the months (perhaps even the week or day) that they are expected in the country, as Japan is very good about keeping records of these things, and the climate is different enough to warrant doing so.
Some people want to see festivals; October seems to be the month with the most, but it depends on which ones you want to see. Some shrines, for example, have the same festival twice a year, but there will be different events.