Watch Season 4 first
Since this entire episode really sets up the final episode of Season 4 it's almost impossible to avoid spoilers so proceed at your peril.
Now how does Sherlock know what Moriarty "is going to do next", is there anything in his weird dream that gives him a clue or two?
He doesn't...in fact Moriarty doesn't do anything next...other than a brief appearances (in flashback), Moriarty does not appear at all.
There are hints about him (which, in fact, may or may not be related to Moriarty at all) but this whole episode sets up...
The reveal of Eurus Holmes, Sherlock's younger sister. Eurus having been erased from Sherlock's memory due to childhood trauma.
There are numerous references to Sherlock having forgotten something important and having to "deep dive" into his memories to recover it.
HOLMES: Sometimes, to solve a case, one must first solve another.
WATSON: Oh, you have a case, then, a new one?
HOLMES (softly): An old one. Very old. I shall have to go deep.
WATSON: Deep? Into what?
HOLMES (softly): Myself.
Transcript
HOLMES: Yes, now you come to mention it, that was quite impressive. (He looks down thoughtfully for a moment, then raises his eyes again.) You may, however, rest assured there are no ghosts in this world...
(Watson nods slightly and looks out of the window. Holmes lowers his eyes.)
HOLMES (quietly): ... save those we make for ourselves.
(He closes his eyes and leans his head back against the headrest.)
WATSON (looking round to him): Sorry, what did you say?
(Holmes keeps his eyes closed.)
WATSON: Ghosts we make for ourselves? What do you mean?
(Holmes doesn’t respond. Watson sighs.)
The fantasy/dream in his drug-fueled 'memory palace' provides hints as to what this might be but you can only make all the connections once you have seen Season 4, specifically the final episode.
Take the scene when Moriarty confronts Sherlock in his rooms... the room shakes, not because it's actually the plane landing in real life, but because the basis of his persona is being shaken to it's foundations.
MORIARTY: Because doesn’t this remind you of another case?
(Holmes closes his eyes.)
MORIARTY: Hasn’t this all happened before? There’s nothing new under the sun.
(Holmes grimaces, his eyes still closed.)
MORIARTY: What was it? What was it? What was that case? Huh? D’you remember?
(Holmes raises his hands and runs them over his face.)
MORIARTY (whispering): It’s on the tip of my tongue.
(He points to his mouth. The room starts to shake again.)
MORIARTY (whispering as he points towards Holmes): It’s on the tip of my tongue.
HOLMES (whispering as he lowers his hands): It’s on the tip of my tongue.
(He opens his eyes as the room continues to shake, then settles.)
Dead women being alive and deep plots against the fabric of reality...it's all there... in hindsight