Get him neutered ASAP for starters. This should have been done around puberty unless he's of breedable quality and/or a show dog.
He is marking things and people that he thinks he should own. "this is mine, this is mine, this is mine and this is mine." You need to show him that, no....it is yours. His food is yours, his toys are yours, the couch is yours, your friends are yours, the door to go outside is under your control and he has to sit first to get most of the things he wants. (or some other skill that he learns in obedience)
How much obedience practice are you doing with him? How often do you react to him? If he is seeking attention, whining, barking etc, do you turn your head and look at him? Speak to him? What does he have to do in order to receive the things he likes and needs for survival? Or does he get what he wants when he wants it?
I recommend that when people come over, you keep him on a leash and have him sit/stay if he's been taught in order for ANYONE to greet him. If he even so much as moves a muscle that looks like he's about to mark, move him away with the leash, let him know that is a no no, "eh-eh!" (nothing harsh or terrible scolding, just "nah....we don't do that." Show him something else that he CAN do instead and be reinforced for, like sit, shake hands. You can take him outside and show him a tree to mark and tell him, "goooood" and give him a treat when he marks that. Be absolutely consistant and keep him on a leash (supervised) when guests come over.
He needs to be in an obedience class again with a positive method trainer with a good reputation. Going to a class isn't all there is to it. You need to practice every single day a couple of times a day and many time during the day....a sit here, a stay there, a heel down the hall, a recall in the living room. He needs to know that you're the one who directs or acts... and he is the one who RE-acts, for the most part.
If he pees on someone when they're lying down, promptly remove him and isolate him for a couple of minutes. If he pees on someone or something in your house, you are too late. You need to watch him much more closely and PREVENT it from happening in the first place. Everytime he succeeds at this, he is being reinforced and the behavior becomes stronger. Intercept him at the first intention of marking and move him toward an alternative behavior for which he can be reinforced for.
He does NOT own anything. You need to take charge and that does NOT include harsh reprimands. It means controlling the things he likes and needs and making him work for them. It means not reacting to his every whim. It means structuring his routine a lot more, more exercise, more training, more direction.
He does not have an attitude. He is not bull headed. He is a dog with normal dog behavior. Dog behavior that we humans don't like needs to be changed or eliminated. It is up to dog owners to train their dogs. Dogs can not be expected to train themselves to have human behaviors. He has no better reason to comply because you haven't given him a reason. Find out what motivates him and use it as his reward and reinforcement. If he's a little hungry when you work with him (no free feeding) and if you use tasty treats, he will appreciate them more. (hot dog pieces, cheese, fresh meat, tiny tid bits) Reinforce behaviors you like, not just watch for behaviors you don't like. Show him what behavior gets him what he wants and needs and what behavior doesn't. Give him a good reason to want to behave the way you want. Make it WORK for him. Find out what motivates him. Something does or he'd lose the will to live.