"You can't teach an old dog new tricks" is fallacy.
When you took this dog in, you probably felt sorry for it. You've probably not given it any boundaries nor limitations because you didn't want to hurt its feelings. The result is that the dog has assumed the leader position and as such, goes pee/poo whenever and wherever it wants. It may have physical problems, but the cheap and most likely problem is that you haven't asserted yourself as pack leader.
Your frustration is understandable, but dogs view emotions like anger and frustration as weakness. You have to be calm and dominant. You have to reclaim your house.
Never let a dog precede you through any doorway, gate or other entrance way. Never continue until the dog is calm and submissive. Do not talk to it nor call it by name when you are setting limitations. This only makes the dog think you are weak and it won't respect you. Don't proceed to step 2, 3, 4 etc. until you are satisfied with its behaviour in step 1. You'd stop your child from peeing on the floor, you have to do the same for your dog.