Can you feel any lumps in his tummy ? ...if you can that's a very bad sign.
Do you have sand , calci-sand , or chips, or bark, or other particulate substrate in his tank ?
....if he's ingested this and it's caused a blockage this is VERY BAD.
40 days with no poos unless he's in brumation and went down with an empty stomache is extremely serious ..
how often do they poo when in brumation ??? never had mine brumate so I'm not sure on this point
.. he needs to be seen URGENTLY by a good reptile vet , just be aware that vet interventions to clear serious impaction are invasive and come with very high levels of risk and are life threatening.
CALL THE VET NOW AND TELL HIM IT"S AN EMERGENCY AND YOU ARE ON YOUR WAY WITH A VERY SICK BEARDED DRAGON , don't waste any more time , his life depends on quick action by you and a vet now.
He's already in a life threatening condition as that stuff is all festering and rotting inside him and can easily result in a very serious systemic infection.
Reptiles are very good at hiding it when they feel unwell , only when they are too sick to hide it (often this is too late to do anything about it) will they show they are sick. I think your have been given the cues he is very ill by way of his current behaviors.
ABSOLUTELY NO MORE SOLIDS FROM NOW ON ===> UNTIL TOLD YOU CAN GIVE THEM BY THE VET.