An enzyme is a protein folded into a precise three-dimensional shape. Bonds between the parts of the protein hold it in that shape, and this includes the shape of the active site.
A high temperature gives the enzyme molecules more energy, so they vibrate more and the bonds holding the protein in shape break. Extreme pH values, either too acidic or too alkaline, also break these bonds. The protein unfolds and the active site changes shape. The substrate no longer fits, so no enzyme-substrate complex can form and the rate of reaction falls. The enzyme is said to be denatured.
Denaturation is permanent. Cooling the enzyme down, or returning it to its best pH, does not bring the original shape back. This is why cooking an egg or boiling an enzyme solution stops the enzyme working for good.