If the PM want's to do anything major, he has to ask Parliament. If the Prime Minister does something and ****s up, Parliament over-rule him. If he keeps doing it, Parliament depose him.
Parliament has final say over just about everything, they leave the day-to-day stuff to the Cabinet and the PM, the courts can 'interpret' laws.
And before any law even gets close to being passed it's gotta go through massive checks, get passed in the Commons and then get passed by the House Of Lords. So they're always perfectly defined to begin with, thus the courts get no say in the matter.
So basically, the PM has day-to-day control but Parliament can always *****-slap him and once they've voted on something their word is final.