i've *been* through this with my dog. we had an unfenced yard with a schnauzer next door who'd charge the fence whenever he saw us (or charge the back window if he was inside). he wasn't always there, but that made it even more of a reinforcement (that whole slot machine scenario). if i took my dog out to potty in the back, the dog might be there. if i took her out the front, the dog might be there. no matter what direction i went on the street, there were dogs behind fences running and barking. (she flipped out at dogs on leashes, but dogs behind fences were and continue to be her biggest trigger.)
and luce would wig out every single time. it sucked. a lot. so i know exactly where you're coming from. my stupidhead dog broke my finger wigging out at another dog.
it took a LOT of work in empty fields, in empty parkinglots, in multiple obedience classes with a trainer who understood what i was working on and who didn't mind if we stepped out of the group until she could calm down, and then eventually moving closer and closer to trigger situations. it took a long time. she's still not "fixed" but she's usually acceptable in public.
it takes patience, lots of good treats, and starting somewhere that your dog is not too spazzed to pay attention to you. it's a gradual process. it's frustrating sometimes that the movement is so slow, but sticking with it, setting your dog up to succeed again and again and again, is the only way you're going to get where you want to be.