I don't remember if you use corrections in your obedience training or not... but I would probably see this as need to proof the heeling vs teach heeling.
At class we have to heel around battery powered toys on the floor, barking-crazy dogs from the agility ring on the other side of the curtain, our instructor throwing dumbbells, wadded up paper on the floor, dots everywhere, or even half the class sitting on the other side of the fence playing with toys, clapping, making noises, or dropping treats or doing whatever they can to set up the training people in the "ring".
The teams in the ring are encouraged to train their dogs to the level of distraction where they can be successful. So they start FAR away from the distractions and work their way closer as the dog gets the idea that their eyes need to be GLUED on their trainer.
At home... like if I didn't have access to the four nearby (less than an hour away) training clubs, then I would go back to drilling heel inside the house in addition to proofing out on our street (when the neighbors are outside + kids are playing) and proofing in front of stores or in safe but public training spots.
I think that is the stage you might be at if he has his brilliant moments and has a general idea of what you want with heeling without distractions going on. He needs to learn that you expect the same focus and effort no matter where you are. And you need to be completely confident with him on leash or off that he will do his part.
I guess my only concern is that if your dog's attention ISN'T perfect at home, then you might need to start from the beginning to retrain heel bit by bit.