Sorry to hear of your horrible insomnia. I have had similar bouts in the past, once lasting for weeks of total non-sleep after reaction to an SSRI. I took near 50mg of melatonin, all kinds of herbs, benadryl, etc. - nothing even touched it. That's when I started getting into neurofeedback and found a social worker locally who offered it. Once learning the basics, I was able to get my own equipment and do some basic training on my own.
You've got to think that those huge magnets in MRI are going to do something to your equilibrium. I felt whacked out in a kind of daze for almost a week after an MRI once. They're using "Transcranial Magnetic Stimulation" experimentally now in depression and testing it on some other things, so it's pretty clear that magnetic energy can really depolarize and affect your brain. I remember reading recently where they've found they can even change people's moral judgments using transcranial magnetic stimulation, affecting part of the brain called the temporal parietal juncture. I'll bet they start using it on prisoners soon, to experiment and see if they can change their behaviors, etc.
So the point is that no doubt can MRI really affect your brain function, even I would suspect causing bad insomnia. Of course, the mainstream people would probably dispute that MRI would do anything to your neurofunctioning, but I think we all know how clueless they are when it comes to diverse populations and very sensitive people. My guess is that over time the response will probably correct itself, but it's possible that it got "stuck" in that pattern. Neurofeedback could probably really help you in either case, either to accelerate things back to normal, or to get you "unstuck." In the meantime, all you can really do is start experimenting with herbs, supplements, meds, etc. from all the great suggestions you'll get here, to find what works best for the symptoms. Hope it resolves for you soon - insomnia is totally awful!