Upgrade a 30 amp breaker to a 40 amp
Yes, if you are running new wire, and ensure it is the proper gauge for the material (copper or aluminum), there is no reason you can't swap out to a higher amp breaker if you have an unused one.  

I would suggest that you go to 50 amp if you're going to this much trouble.  40 amps is a bit of an odd duck, so you might as well have 50 amps available because you could end up with an appliance or tool that needs it.  The most common residential outlets will be either 30 amp, or 50 amp for 240.  If you're running this to another subpanel I guess that doesn't matter, but I'd still suggest scaling the circuit for 50 amps.