Statistical Mechanics of Emergent Phenomena: Phase Transitions in Equilibrium and Nonequilibrium Systems