Looking at the rules for Surprise on page 189 of the 5e PHB. It says that a creature is surprised if the enemy's stealth check beats their passive perception. It then goes on to say:
Any creature that doesn't notice a threat is surprised at the start of the encounter
So that's pretty straight forward, you hide, roll stealth and beat the passive perception of the monster and you get a surprise round.
Now I have 2 other scenarios I'm confused about:
What if the creature is actively looking and therefore makes a perception roll instead of relying on passive perception? If the stealth check beats the perception check, does the stealth user still get a surprise round? And,
What happens when you use the hide action and succeed or turn in visible in combat? Would the enemy presumably lose track of you and be surprised if you attacked from behind?