I’m don’t claim to be Yngwie, but I can improvise at a fairly high speed. You correctly point out the two main issues: Being able to play the notes, and knowing which notes to play: Technique and music.
As far as knowing which notes to play, for me it’s mainly a question of fretboard maps. I have about a dozen different mental maps to cover the fretboard for any given tonality, and I switch between them as necessary to support my improvisation. They come in two flavors: pentatonic and diatonic (others would also include harmonic minor, etc.)
The standard pentatonic boxes and the CAGED system fit into the pentatonic flavor, along with the 3NPS pentatonics and a few other maps. Except for CAGED, they all have exactly the same notes, but they are grouped differently. For example, I have a map that gives me all of the pentatonic notes on any given pair of adjacent strings (like the standard boxes turned sideways, it lays out the scale all the way up and down the fretboard on just the E and A strings, for example), and another one that works its way diagonally up the fretboard from position IV to position XII in the key of A minor.
For diatonic I have the 3NPS patterns, the position-based boxed patterns, Claus Levin’s 4NPS scales (so useful for shredding), another 2-string pattern, etc.
The pentatonic patterns fit over the diatonic patterns in a few different ways, so you can align your E minor pentatonic with E Dorian, E Phrygian, E Aeolian. (In other words, each diatonic pattern supports multiple pentatonic patterns without going out of key.) So you have to maintain your pentatonic maps and your diatonic maps separately, and practice switching between them in different modes. Practice switching between E pentatonic and E Aeolian, then practice switching between E pentatonic and E Dorian, etc.
I can only navigate one map at a time, but I can easily switch from one map to another, because I practiced switching maps while improvising. I choose which map to use based on the sound I want to make, and the reason that’s reliable is that I have practiced improvising separately from technical practice. In fact, before CTC that’s pretty much all the practice I did. Technical exercises didn’t work for me, so I just improvised all the time. (Thirty years of bad technique gives you a lot of time to develop fretboard maps.) When I learn other people’s songs and licks, I always fit the music into one or more of my maps. Otherwise I won’t remember it. By consciously fitting the music into my maps, I am reinforcing the connection between my ears and my fingers. Over time, that builds into fluency and vocabulary.
A funny thing happened once I got my right hand together. My improvised phrases got much more interesting. By becoming more fluent with alternate picking, I am able to improvise phrases that I would previously have struggled to play at all, much less improvise. My musicality has increased greatly, because my technique can now much better support what I hear in my head. Learning how to chunk effectively has played a large role in this as well.
Yngwie seems to have similar maps. They are described very thoroughly by Troy, and they have names like ‘The Sword’, etc. If you want to sound like him, internalize these licks and then start improvising with the same set of notes.
This is my approach, which is different than the memorize-a-million-licks approach, which has also worked well for lots of people.