They are privateers. That is to say they are pirates without sanctions, granted special license to ply their trade by the WG in exchange for a portion of their earnings. For a comic Oda has said "isn't that deep", the existence of the Shichibukai hint at a subplot within the teen audience range, as opposed to the preteen audience.
The World Government, like any government, is charged with maintaining civil order and law. The Golden Age of Piracy, with its countless hordes of pirates looting, pillaging, and raping (off-screen, of course) is too large a threat for their forces to control, let alone destroy. They simply lack the resources and manpower to do it, especially in the face of superhuman pirates.
The best course of action the WG could take therefore, was to recruit anyone whose strength was sufficient to crush down pirate crews with ease. Since not all of these people were willing to enlist, and since many were determined to live as pirates, it was decided that a certain amount of leniency would be shown to the strongest pirates, in exchange for their help in crushing the hordes of weaker pirates. This way, the Marines would not be overrun and all civil order destroyed.
Between the Yonkou and the Shichibukai, there are at least eleven pirates or pirate groups that pose a serious threat to the WG. If the Marines were committed to a war against the Yonkou, it is believable that they would win it; however, they would be so weakened by it that they would be unable to continue fending off all of the other, weaker pirates. Moreover, the Shichibukai could take advantage of such a situation to attack several countries- thus cutting off vital resources from the WG, further weakening their position. And if the Yonkou attacked either of the other two, they would be wiped out by whichever side lasted longer. So all three sides are constantly in check, unable to do more than glare at each other or scoff. A balance is maintained so long as no side falters. This is why Kuma worries about Blackbeard's promotion: he was a former underling of one of the Yonkou. The fact that he willingly betrayed his own side to join another raises questions about his loyalty to the side he joined.