Conifold transitions in $M$-theory on Calabi-Yau fourfolds with background fluxes