Dissecting the dynamics of epigenetic changes in phenotype-structured populations exposed to fluctuating environments