Firstly - Welcome to the forum Will
Error code 22 is not a common fault, but it does happen and could well be the reason for the surging as the failsafe is for the ECU to assume a fixed air intake temperature at 20C. If you're much outside of 15-25C the bike will surge a little.
Most commonly this error occurs when a Kev mod is fitted and the connections fail where they are spliced into the AIT wiring. It has happen to me and a few others I know of. All you have to do if this is the case, is find the Kev mod (a little black box with a dial on top), trace the wiring back to its connector and re-make the connections. Sometimes they are soldered, but more often than not, a block connector is used.
If you've recently bought your bike, and you can't find a Kev mod under the seat, then it may well have had one fitted at some point in the past and it has been removed and sold on separately from the bike. It is not unheard of for people to make a bad job of reconnecting the two ends of the AIT where the Kev mod was fitted (in series). If this fails then you will see a code 22.
It is highly unlikely that the AIT sensor itself will have failed.
What I would do first, is check for a Kev mod and check closely the wiring to the AIT sensor which inserted into the back of the LHS of the airbox. You will need to remove the seat. Look at the intake hose and look to the left. I'll try and find a picture for you...
Here is the AIT sensor and it's soldered Kev mod connections. The blue/black wire is the one that gets cut to fit the Kev mod in series and this is potentially the area you should investigate. You can just see on the left the hole it plugs into...
The kev fuelling mod looks like this...
Its function is to kid the ECU into thinking it's colder than it actually is, thereby richening the fuelling.
Read this thread for full details on the mod and how it is fitted:
http://www.xt660.com/showthread.php?t=11641