To avoid hypothermia, wear layers of clothing, stay dry, and carry waterproof clothes. To avoid heatstroke, wear lightweight clothes, stay hydrated by drinking enough water, and take breaks in shady spots. Avoid hiking during extreme weather conditions.