Optimal Battery Controlling for Smart Grid Nodes ∗