What happens to our body when we undergo a sudden temperature change from 40℃ to 20℃?
Disclaimer: the answer is very broad and covers both the situations I am confident about, as well as those I understand only superficially. 

The outcome depends on particular temperatures.

Example - cold shock response: "Cold shock response is the physiological response of organisms to sudden cold, especially cold water. In humans, cold shock response is perhaps the most common cause of death from immersion in very cold water, such as by falling through thin ice. The cold water can cause heart attack due to vasoconstriction, the heart has to work harder to pump the same volume of blood throughout the body. For people with heart disease, this additional workload can cause the heart to go into arrest. Inhalation of water (and thus drowning) may result from hyperventilation. Some people, due to body type or mental conditioning, are much better able to survive swimming in very cold water." But: " A person who survives the initial minute of trauma (after falling into icy water), can survive for at least thirty minutes provided they don't drown."

Sudden heat at entering sauna - I am not sure, but probably it also may cause heart attacks. Recent heart attack is a contraindication for sauna visits. Healthy individuals do O.K. due to thermoregulation mechanisms in the body.

As we move to more extreme temperatures, where the thermoregulation of human body simply has no chance at all to keep up, you can percieve the human body as a chunk of meat. The proteins denature, the water in the body gets boiled. The meat gets cooked, turns coal like, burns to ashes... Or by freezing, the water forms crystals, damages and breaks the cells. Eventually the meat freezes to be stone hard and does not change for a long time if kept at such temperature.