I've pretty much done that:
I have solar panels and a hybrid inverter with batteries. It has a backup output to power critical loads in case of a blackout.
Compared to a generator, solar is silent and will also shrink your utility bills. So unlike a generator that you use only in a blackout, you use it all the time. However, it is intermittent and dependent on weather: if you want a guaranteed output to run your critical loads, then you must install many more solar panels than you actually need. Even then it is not guaranteed: if the panels are covered in snow there is no power, if you get a week of really bad weather, you can expect a 10kWp installation to produce 1-2 kWh per day which is quite useless. So the viability of the solar option as a backup really depends on your climate and should be studied carefully before writing a big check.
Right now the critical loads are: two freezers, plus the heating circulators and associated electronics.
The inverter will automatically power critical loads, but the heating changeover is manual. Normally I use a heat pump, but that is not usable in a blackout situation. I also have an old wood furnace that was already there when we bought the house, so we left it in. In case of blackout, I simply turn off the heat pump to prevent it from restarting automatically when the grid comes up, then load the wood furnace and fire it up. The electronics that control the circulators and underfloor hydronic heating then work on power from the inverter, hot water from the wood furnace goes into the underfloor heating, and I still get heat.
If you intend to do that, you should measure the total power consumption of your critical devices: freezer, heater including fans and circulator, and add some margin. The simplest way is to put each device in turn on a wattmeter socket and check the maximum reading. For example a freezer will, once in a while, use a lot more power to defrost so if you just look at the wattmeter for a minute you'll never know. The inverter should be able to provide the maximum power, otherwise it'll shut down. For motors, make sure to measure the startup current and check if it is much higher than the running current.
Then check your loads: most likely you will have some AC asynchronous motors (circulator pumps, fans, freezer, etc) and these run much better on good sinewave power. Newer inverter-based freezers and circulator pumps should be much less picky.
This is important because if you get a cheapo generator that outputs dirty power that only barely looks like a sinewave, your asynchronous motors will make strange noises or perhaps work terribly or not at all. Electronics may also crash if the generator has poor regulation.
So you should definitely test everything. If you use an inverter, it should be pure sine wave, because asynchronous motors strongly dislike square wave current from "modified sinewave" inverters.
You could also use an inverter generator.
However the power use from all your critical loads is likely to be much lower than the generator output, which means it'll waste a lot of gas to just keep running. This might be OK but it's also very noisy. So you could use a generator to charge inverter batteries, or one of these big Lithium power banks, and then use that to power your heating while not running the generator all the time.
In case of a large blackout, it is not guaranteed you will get gas. If you have a large heating oil tank this is not a problem.
Gasoline generators are annoying, because gasoline is annoying to store. It evaporates, when it's old it no longer works, and basically a gasoline generator will probably not work when you need it unless you take the time to do proper maintenance, rotating gasoline stocks so it's always fresh, etc. That's a problem with emergency equipment that rarely gets used: you forget about it and then when you need it, you find it's quite dead. So before buying you should look into that. Propane generators do not suffer from these issues, and I hear diesel is also more convenient.
To make sure everything will run properly in case of a blackout, I ran the critical loads on the solar backup for a week, it's much easier to debug the system when there's no emergency.