Back off holiday and managed to play a bit yesterday. I bled the fuel rail and it hasn't cured the problem. Once again, as soon as the fault code shows up, the surging issue stops. It also all resets and starts again when the engine is turned off and on again.
I'm now convinced that the two are linked. I looked at the shift linkage and noticed that the shifter was not on the central mark when in neutral and with the engine off would not engage forward gear. It appears that when I took the side mount shift box off the other day to fit cable glands that I didn't get the cable back on the pin correctly and it was not sitting in the correct place. I've rectified that but haven't run the engine up again. I suspect that the shift sensor was on its limit of position and was giving an on-off-on signal to the engine, which was thus assuming the gear was being engaged and dropping the revs intermittently, again assuming that there is built in protection to drop the revs to below about 2000 when gears are engaged. I'm also assuming that after a few mins of oscillating signals from the sensor, the engine has assumed it is knackered and started to ignore it, hence the engine rev'd freely when the fault was detected.
I will hopefully get chance to fun it up again by the end of the week so time will tell!