If you have a backup battery, first your excess energy goes to charge the battery. In all other cases it goes directly into the grid, and with your utility's net energy metering program you are credit for the energy the solar generates. Then when you go to pull energy from the grid, you're actually pulling from the credits you've generated by exporting power.