You will need a charge controller for the off grid end of things. A grid tie inverter
(here is what I am looking at) to take the panel output and convert it into 120/240 volt AC - and grid tie it. A simple inverter will blow if its output is attached to a live grid. The last thing you will need is a relay or double pole switch to either connect the panels to the charge controller, or the grid tie inverter. A relay with a 120 volt coil on the output of the inverter will do the job, and as soon as you unplug the panels - switch to off grid mode, plug back in and they switch to grid tie mode. Your onboard converter will keep the batteries charged when grid tied (and be powered off the grid tie inverter during the day), and the charge controller will charge them when off grid.