There is one relatively simple optimization you can do, for a start, and it will likely make a big difference...
If you analyze the equation:
n² + an + b, where |a| < 1000 and |b| < 1000
you need to solve it for where n² + an + b is prime.
The first n value to use is 0. 0² +a0 +b is b, thus, in order to process any values, it is clear that b needs to be a prime number (and not negative either...).
Thus, you should rearrange your loops, and your outer loop should be on the first k prime numbers in your set, where the k'th prime is < 1000.