Making errors is an unavoidable part of the process, as any researcher will tell you. But it's important to have good quality control over your own work.
We can roughly divide errors into two categories: errors that result from a lack of attention, and errors that result from a lack of understanding. For the first kind, it's simply a matter of taking more care. If you think a document is airtight, wait an hour (or more if it's a long document), come back with fresh eyes, and proofread it again before sending. If you continue to find errors in your work after it's too late, continue adding iterations.
The second kind--which I suspect you're also making, because your paper wouldn't have been rejected twice if its only problem were nitty-gritty mistakes--is harder to deal with. It's fine to not understand things. If we understood everything already, it wouldn't be called research. But it's very important to know what you understand and what you don't understand. If you're not sure a step in your proof is justified, don't take it. (On the other hand, thinking ahead and asking what you can do with the step if it IS justified, is fine and sometimes necessary. But you do eventually have to come back and justify the step.) And it's fine to ask for help when you don't understand something. It's important to be able to ask your advisor stupid questions--that's what he's there for. And your advisor should read any paper you're submitting before you submit it, or at the very least, you should give him a detailed report on it. He's right to be frustrated that you went behind his back.
Finally, even if you do everything "right", mistakes will still happen. After Andrew Wiles' earth-shattering proof of Fermat's Last Theorem, a mistake was found, and it took Wiles over a year to fix it. There's no shame in making mistakes, as long as they're not too frequent or too obvious.