Not sure about the leg except that sometimes it's a "oh that feels good" reaction to scratching the ears. The rest sounds like your dog might need an ear flush from the vet. It is done with a mild sedative and all told is about $160. Then, once a week (if your dog has floppy ears) you can use a product called Veterinarian's Best. It is an all natural ear relief wash and drying solution. They contain tee tree and other soothing things, you can buy both at the regular pet store.
The scratching and shaking his head sounds as though he has an ear infection or ear mites. Not sure about the leg, though.