You say you are a beginner and I would lay odds on that this horse is getting away with a lot of little things that have given him the idea that he can get away with some major issues.
Horses are like children in that they will get away with what they can and keep pushing the boundaries out until they are totally obnoxious.
You need to get tougher with him. When he spooks, get cross with him, if leading give him a hard jerk on the halter rope and make him go right up to whatever he is looking at. Do the same if you are riding him. Be very firm but not angry. Be determined, horses sense that.
In the stable or whenever you handle him, make sure that he does exactly what you ask the moment you ask it. If, say you ask him to move over and he doesn't, give him a hard shove and a slap so he does. Make him wait if you open the stable door until you invite him to go out.
Push him around rather than allow him to push you.
The tougher you are, providing it is fair, the better behaved they are.