Grid-tied systems can be upgraded to include a battery backup:
A bank of deep-cycle batteries. The backup battery is charged by both the grid and the solar panels. In the event of an outage, the backup battery will need to be switched on either manually or with an automatic system to provide backup power to the building.
On and off grid solar (Hybrid System) working way:
Inverter transfer solar panel DC current to AC current, supply solar power to run loads directly, if solar power is excess, the power will charge to battery automatically. When the battery power is full also, inverter will send the excess power to grid.
When the solar panel only generate few power, it will switch to grid, supply grid power to the load (by pass).
When the grid shut down, it will switch to off grid status, transfer solar DC power to AC power, supply solar power directly to the load. When the solar panel cannot provide enough power to the load, it will use battery power.