Thermodynamic model of heterochromatin formation through epigenetic regulation