I am trying to take out 5V from 24V using Z package, to supply the microcontroller.
Using the equation, the power dissipation is around 5W, do you think it will work with a heat sink mounted on?
The graph gives a max of 4W with an infinite heatsink and an ambient temperature or 0 degree Celcious, so no it can't work.
Your input/output difference in high so you should consider a switching regulator, for example LM2596 or LM2676 , this will increase efficiency and reduce the generated heat.