As sad as it may be, I don't think that there is general rule and it ultimately comes down to just pure usage. The "es" is wrong in all your example except 3. Not just optional but wrong. However, there are examples with the exact same structure where it is optional
Ich genieße es, dir zuzuhören.
Ich vermisse es, einen Strandspaziergang zu machen.
Here, the version with "es" is actually better. Without it it would sound truncated and in the second example, leaving it out can lead to grammatical confusion.
Ich vermisse einen Strandspaziergang... oh... zu machen.
As far "das" and "es"...no they are quite rarely interchangeable. If the "es" has only grammatical function (as in 3) or is optional (my example) then you cannot replace it with "das" because there isn't really anything "das" could point at.
Only if the "es" is an full blown pronoun that refers to something that is not part of that very predicate, then you can replace it by "das" to get a stronger focus on it.
But mind you, if you put emphasis, there has to be a reason to do so... for instance pointing out a contradiction.
Ich habe versucht, dir zuzuhören, aber es/das ist mir nicht gelungen.
In your third example, only "das" is possible, because it is a demonstrative pronoun that is "filled" with the relative clause. "Es" doesn't work like that.