Just luck that prevented my stubbornness from causing real damage. In a way I'm glad I learned my lesson while I was stuck at a relatively low weight,though.
Basically a bunch of simple dynamic stretches of the hips. E.g. put one foot forward and bend over as far as you can with a straight back, trying to touch the floor, and up again, take a step so the other foot is out front, and repeat. Or stand and hold on to something and swing one leg back and forth as well as left/right on front of your torso.
To that I added "asian squat". Just practice sitting in the squat position as long as you can as much as possible throughout the day.
It took me a couple of months to get to the point where my back squat started going up with good form. In less than 6 months I went from hurting myself at 60kg to doing 5x5 at 150kg without pain (though keep in mind that at I had been stalling at 60kg for ages and done what I could to compensate with other exercises).
I'd recommend a physiotherapist and/or a personal trainer you are very sure knows squats properly. A lot of personal trainers are clueless about strength training. If it's technique, the trainer is your best bet. If your problem is actually flexibility, a physiotherapist or a personal trainer that's experienced with e.g. gymnastics or yoga might be just as good for you.
I can deadlift 220 kgs but have hurt my back moving house a few times, carrying awkward boxes, furniture and appliances up and down staircases and such. It's so important to have the weight close to your hips and not out in front of you--but that's not always possible with an awkwardly shaped weight.