New probe of magnetic fields in the prereionization epoch. I. Formalism