This is true, but making batteries isn't without its own environmental impact
If "gasoline" is made from solar power, it will almost certainly use carbon from the air (gasoline is a hydrocarbon, afterall), so it would be carbon neutral if it released the carbon back into the air.