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.