It's not hard. There is type of inverters that called "Hybrid inverter", I have one that can keep power off-grid or on-grid or even on-grid in import mode only (so only import any needed power without exporting...), and it can work off-grid even without battery (from solar) but that is not recommended unless you know that your load is much smaller than the solar output, even small lead-acid battery can mitigate this issue.
The way the inverter work is that when the grid goes off it will automatically switch the power export off and keep the load running from solar and/or battery in isolated mode.