I think the magic solution for my cats was a q-tip dipped in a solution of light mineral oil with (if I recall correctly) a touch of boric acid, the same stuff you can mix with rubbing alcohol to make after-swim ear drops. Any competent vet can get you the exact mixture, but you usually don't need any expensive medication unless the mites and scratching have left the ears infected. Carefully pour in some oil and then mop it and the mites out with the q-tips, being very very careful not to dig into the inner ear canal. If you're still digging out residue after the oil is mopped up, just dip the q-tip into the oil and have at it again. Don't worry about getting it all at once if the pet gets agitated, just repeat the next day.
I pulled mites, eggs, and then dead mites out of my cat's ears for a week or two every year because they were outdoor cats and always getting into trouble. If you catch it early enough, when they first start scratching, then it doesn't take very long to fix. When it gets to the point of black crusty flakes filling the ears and coming out whenever they scratch, you're going to be cleaning the ears for a couple of weeks before all the mites are gone and any damage is healed.
edit - to prevent damage to the cat's inner ear and to my skin, I usually knelt sitting on my knees with the cat firmly pinned between my knees, very gently half-sitting on the cat's rear legs and the head poking out near my knees. This minimized the 4 sharp appendages on the ground and gave me the max leverage on the cat's neck and ear. I strongly recommending playing with your pet a little to find a suitable "hold" position before trying any type of home medical treatment, as this will save your skin in the long run. I had to treat my cats for multiple medical problems while growing up, and I ended up using 3 different hold positions that were painless for both me and the cats. Again, a vet should be able to provide guidance and you can find a similiar way to pin a dog.
If you can't figure out any other way, roll the pet up in a towel with just the head sticking out when it's tired or sleeping. If your pet doesn't sleep, I've heard that a tiny amount of beer might do the trick but I never had to try that out myself. My Mom wasn't strong enough for the hold position required to treat an abcess under my cat's jaw so she usually calmed him down by combing his fur then wrapped him in the towel before pissing him off by cleaning the wound.
If it's a large dog or an otherwise strong pet, you may need a helper to sit on the pet and/or distract it while you dig into the ears. They make large q-tips with plastic stems that aren't as likely to get jammed into the inner ear, so you can try those out as necessary.