Battery management of electric and hybrid vehicles