Preparing spells
From Monster Manual, page 10.
The monster has a list of spells known or prepared
from a particular class.
This part basicallly means that there are two options:
- monster has spells prepared (he knows even more) which resembles clerics, wizards
- monster has spells known, which looks a little similar classes of bard or sorcerer
Continueing.
You can change the spells that a monster knows or has prepared, replacing any spell on a monster's spell list with a different spell of the same level and from the same class list. If you do so, you might cause the monster to be a greater or lesser threat than suggested by its challenge rating.
From Monster Manual Errata:
The monster is considered a member of that class when attuning to or using a magic item that requires membership in the class or access to its spell list.
Player Handbook page 201
Before a spellcaster can use a spell, he or she must have the spell firmly fixed in mind, or must have access to the spell in a magic item. Members of a few classes, including bards and sorcerers, have a limited list of spells they know that are always fixed in mind. The same thing is true of many magic-using monsters. Other spellcasters, such as clerics and wizards, undergo a process of preparing spells.
Notice, that the word "many" is used, not "all". If you read Monster Manual, you will notice that there are 2 types of casting for monster: innate or one that has spells from one of the spellcasting classes. Since word "many" applies only to a part, it is clearly means, that only one part of the magic using monster does not need to prepare them. That part are monsters with innate spellcasting. The other part goes with the rule:
Other spellcasters, such as clerics and wizards, undergo a
process of preparing spells.
Morefurther, to prove my point:
Drow Mage, and Drow Priestess of Lolth are basically Drows who took some classes of wizard or cleric, since their innate magic is not so powerful(you can easily create such a character like it was a PC). Notice that both of them are not called "wizard" or "cleric" but spellcasters with prepared spells from wizard/cleric list.
If someone is still uncertain, there is a reply from wizards:
Basically this means, that you should treat the monster depending what kind of spellcasting they have.
Example:
Spirit Naga must prepare it's spells like a wizard does.
Derro Savant (Out of the Abyss, page 60) doesn't have to prepare it's spells, as he is treated like sorcerer.
Recovering spells
From Player's Handbook, page 201:
Finishing a long rest restores any expended spell slots (see chapter 8
for the rules on resting). Some characters and monsters have special
abilities that let them cast spells without using spell slots.
This means, unless the monster has a special ability to regain spell slots, it needs a rest.
Such an example would be Lich:
On initiative count 20 (losing initiative ties), the lich can take a
lair action to cause one of the following magical effects; the lich
can't use the same effect two rounds in a row:
The lich rolls a d8
and regains a spell slot of that level or lower. If it has no spent
spell slots of that level or lower, nothing happens.
Excellent Idea! (MAYBE there's a loophole)
First of all, I'm impressed by this strategy! It's a great idea, and turns the tables on the Beholder extremely well. You might have some trouble targeting the Beholder from within the cloud yourself, but characters normally know where other creatures are during combat (the fact that the Beholder hovers may complicate this, but probably not unless the Beholder takes the Hide action).
There is a small potential loophole I noticed, but it's not ironclad (more open to interpretation).
Legendary Action & Lair Actions
The Beholder can use its eye rays with its Action during its turn, but must choose targets it can see. However, it can also use its eye rays in two other ways: one is with a Legendary action at the end of another creature's turn. This legendary action is described as follows:
Eye Ray. The beholder uses one random eye ray.
It can also use lair actions, one of which is the following (MM, p. 27, bold added):
Walls within 120 feet of the beholder sprout grasping appendages until initiative count 20 on the round after next. Each creature of the beholder's choice that starts its turn within 10 feet of such a wall must succeed on a DC 15 Dexterity saving throw or be grappled.
Note that neither of these descriptions requires the Beholder to see its chosen targets.
It's likely that the definition of the eye rays given in the Actions section of its description is meant to apply to the other (Legendary) rays as well. But this is ambiguously worded, and open to interpretation. Clearly, some parts of the description of the eye rays must apply (or else there would be no limit to the range of these Eye Rays, for example): exactly how much applies, though, is ultimately up to the DM.
Even if its lair and Legendary actions do not require sight, note that your strategy would pretty much halve the amount of opportunities that the Beholder has to target creatures directly (as opposed to lifting a heavy object above a character while they are in the Antimagic Cone, and dropping it). This makes this strategy an excellent idea in any case.
Best Answer
Yes, you can learn a demon's name this way.
Dominate monster could be used to compel a demon to reveal its true name, but the demon gets a saving throw (and most demons have Magic Resistance, so they will have advantage on the saving throw). Since revealing its true name is "obviously harmful" to the demon, suggestion would not be able to compel it in that way.
The most common use for a demon's true name is as part of the 4th-level summon greater demon spell (in Xanathar's Guide to Everything):
Gate can also be used to summon a specific demon whose true name is known — perhaps one too powerful to be summoned and controlled via summon greater demon:
Note that in the case of gate, knowing the demon's true name doesn't help you control it; likewise other spells like planar binding or, indeed, dominate monster are not more effective if the demon's true name is known.
This answer has been edited to include new information from Xanathar's Guide to Everything, which includes spells that specifically benefit from knowing a demon's true name.