The best way really depends on your electric utility company rates and rules.
In my case, I only get about 50% credit while the sun is shining vs my evening rate to buy power. Overnight is a toss up. But since they don't credit the taxes and NBCs (Non Bypassable Charges). So even when the rate is the same, it saves some money to self consume power from the batteries. When my solar production just matched my usage, I would charge the batteries with all my extra power over the house usage while the sun is up, and then my house would run off the batteries from sunset to sunrise again. In the spring and fall, I would top up the batteries and then export the rest for some credit. So in the summer and winter when production didn't quite make it, I would use the grid energy credits. My total electric bill did end up zeroed out with a little credit left for the last 2 years.