True, but solar panels are a capital cost (ie a one-time cost) whereas electricity/gas is a consumable.
There are lots of variables, but return on investment in solar is around 14% annually for me. It'll vary from place to place, so you need to do your own math.