A General Energy Balance For Battery Systems