I think the key is trying to keep roughly the same cadence, which is hardest when the terrain changes from flat-out can't-pedal downhill to abrupt steep uphill. I would try to maximize my speed downhill, pedalling if possible (with resistance, spinning without resistance just makes me unsteady), and as soon as my speed drops a little try to downshift and find the right gearing for that speed, the next moment downshift a bit more to that right gearing, etc until you're either at the top of the hill or on your lowest gear.

I'm trying to imagine it and I think that coming fast into a steep hill I maybe downshift in 3 or 4 separate "sessions", several gears at a time, if that makes sense, before ending up on my smallest grinder gears. It comes with practice, judging at which speed you can use which gear, or rather - how much slowing down needs to generate how much downshifting.

I would think it helps to practice on the same hill or the same route, and try out several strategies. Downshifting too much is rarely a problem, you can just shift up a bit, but downshifting too little will have you struggling to shift again under pressure.

Oh, and long hills really are all about just grinding along, all momentum lost... Sing to yourself, stand a little, sit a little, practice reaching for your water bottle, don't worry about speed :-)