How much experience do monsters, NPCs or other generated creatures have for the use of spells and item creation? When a demon uses wish, how does it spend XP, and from what pool does it draw on? Is there a rule I am missing on this or is this just a WTF moment?
Typically, this sort of thing is handled by DM fiat. If you want one of your NPCs to craft a magic item, then they can. The whole reason that XP costs for that kind of thing exist is to make it so players don't have an unlimited supply of powerful magic to mess around with, and that's not a problem with NPCs. In addition, specific XP values are very rarely calculated for NPCs, with the possible exception of cohorts.
The only place that I know of in all of 3.0 and 3.5 where Xp for crafting for NPCs is mentioned is on Page 29 of Deities and Demigods, where it says that gods have 30,000 XP per week that they can spend on crafting and spellcasting. If you want to keep track of NPC XP for crafting and spellcasting, then you're going to have to create your own system for dealing with that kind of thing.
That said, you could totally institute a rule that limits how many magic items NPCs can make, if you want. Maybe say that each NPC has half of the XP needed to gain a level available for crafting at any specific time, and have that amount slowly regenerate, perhaps at a rate of 5% of the XP needed to gain their next level per week or so. This is all very ad-hoc and untested, but it's perfectly viable for yo to add this kind of restriction in.
Alternately, you could let the treasure guidelines deal with it. If a particular enemy is supposed to have 750 gp worth of treasure (for example), you could instead give them a wand of magic missile that they've crafted. To the players, it makes no difference, but this way you can better justify the gear that enemies are carrying.
One thing to note, where spells with expensive material components or XP costs are concerned: spell-like abilities don't need material components or cost XP. If a genie uses wish, they don't spend any XP to do so, they just cast the spell. If a demon has the spell-like ability to grant a wish, it doesn't cost them anything to use.
You've essentially asked two very different questions here, so I'll address them as such; then I'll address the concept behind them.
It is important to note that most spells with an XP cost are not particularly useful in combat and in a standard (Grayhawk-style) campaign world they can be easily purchased out of combat. When there is an XP cost, it seems to be standardized at 500XP per spell level beyond 4th. A wizard receives only 1 fifth level spell at 9th level. It takes 9000XP to reach the next level. This means that, daily, a wizard of this level can only expend 1/18th of the cost to reach their next level. Admittedly, the potential XP drain relative to XP per level goes up as the character levels up but it is equally unlikely (and unhelpful) for the NPC to stock up on XP draining spells. However, even a 20th level wizard casting the allowable 4 Wish spells in a day will only expend a single level's worth of XP. But let's be honest, while you're character might have Wish as a backup (if they've reached that high a level) in general there are better spell choices available for everyday use. This is why I recommend you simply do without these spells.
The treasure generation tables cover this. Any loot the NPC might use is generally considered to be part of the CR for the encounter. There's also the potential gain to PCs of defeating the NPC to consider. Their gains in the case of non-expendable items are directly proportional the benefit the NPC gained when facing them. For expendable items, this mostly means that it benefits the party to defeat the NPC as soon as possible.
Some non-fiat options
In general most NPCs are going to disappear after a single encounter and almost no NPC is going to be encountered with such frequency that they've had time to craft a magic item, but not recover the XP. Therefore...