Statistical mechanics approach to the electric polarization and dielectric constant of band insulators