It is an expression used usually alone as "¡Con dos cojones!" but you can use it also inside a sentence.
And you can say it when someone suceeds in achieving a goal normally because of his/her tenacity, courage, struggle, etc.. You can use it also in any situation when someone suceeds and you find it funny, surprising, etc.. Very general.
In spain also you can heard "Ole tus huevos", that have the same meaning. "Ole" y the same word that is used in bullfighting, very spanish. In addicion, the two phrases are very vulgar, also very popular
OK, all of above is more or less the meaning and also could add: Con dos cojones translates 'With two balls' Balls meaning Nuts or Testicles. As in other word, "Show them you got Balls" or "No Balls No Glory" So if your planning something big like making the World a better place well con dos cojones and it could be done. OLe
How come he did that!?(which is bad)
For example for this one:
Someone owes me 140$ and ask me for another 30$ more..con dos cojones! Or someone says really bad things about me without my knowledge (is this expression correct?) and later he praises at me.. con dos cojones..