How would it switch between if endothermic and ectothermic and in between and how would it be able to create different temperature in specific areas in the body?
Cross-posted from Scientific Speculation Codidact; the answer there is probably more up to date.
Yes, it can – they're called “heterotherms”. As with most "can an organism" questions, you only need to look to find some organism that already does this.
- All hibernating animals (many bears, many small rodents) reduce their metabolism when they hibernate, to some degree.
- Likewise, most æstivating animals (lesser dwarf lemurs, ladybird beetles) reduce their metabolism enough that they become poikilothermic.
- Some creatures undergo cryptobiosis, where their metabolisms just… stop. Tardigrades are the canonical example, but some lobsters do this too (when the surrounding water starts to freeze). These are all normally ectothermic, though, so they probably don't count – though it's not inconceivable that a normally endothermic creature could undergo some form of cryptobiosis.
The best-fitting creatures, however, are probably bats. Many bats reduce their metabolisms to poikilothermic levels when they're resting (inactive), which means they do this almost every day. If there was some handwavey selection pressure to make this behaviour deliberately-controllable, then we could very well have bats able to control their own metabolism to this extent in real life. And I think that's pretty cool.
Having a different metabolic rate in different parts of the body is really common by comparison. When your fight-or-flight response is triggered, your muscles generate more heat and your brain generates less. Likewise, shivering generates more heat in certain areas of the body. To a limited extent, you (an approximately average human) already have the ability to do this.
Brown adipose tissue is even more effective at wasting energy as heat, but (most?) humans don't have conscious control over its behaviour; it's governed by the sympathetic nervous system. Your creature could be able to control it deliberately, though; this, coupled with an overall reduction in metabolic rate, would let a creature make a pretty large temperature gradient across its body.
Thus, an organism with fine-grained control over its metabolism and the heat it's generating is entirely plausible. Though make sure you constrain yourself to the Second Law of Thermodynamics: thinking, being a non-reversible computation, generates heat, so a cold brain means slow / small / few thoughts.