Can I use gafana Group by Month and Year?

Now I can figure out the energy consumed every 1 hour by using

SELECT max("value") - min("value")  FROM "state" WHERE ("entity_id" = 'a_energy_total') AND $timeFilter GROUP BY time(1h) fill(null)

Is it possible to figure out the energy consumed every (month/year) ?

No, there is no month or year interval. There are quite old feature requests asking for this in the Grafana project.

The closest you can get is 30 days and 365 days respectively.