Talk to the Referee
The referee should not be making calls maliciously and is likely unaware of his own bad performance. While pointing out a bad call in a rude way won't help your cause, mentioning a problem in a more general way can alert the referee to your concerns and give him things to watch out for. For example, if the referee is calling fouls unfairly against your team, ask the referee to watch the other team for drawing fouls. A polite complaint can garner sympathy to your plight depending on the ref and is the first step to correcting bad refereeing. Talk to the other referees on the court as well to address bad calls if a specific ref is to blame.
A bad referee is more likely to penalize you for aggressive play in basketball since the game is not considered a contact sport. As a result, give the other team a little more space when dealing with a bad referee to try to prevent unjust foul calls and other penalties. There is a risk associated with this because good players take advantage of any extra space they have to either advance the ball towards the net or go for a shot. However, playing more conservatively for a little while may placate an overly sensitive referee and get him to start calling things more fairly.
While two wrongs don't make a right, one bad call sometimes counteracts another. As a result, try drawing fouls if you have a referee that is overly eager to blow the whistle during a game. If an opposing player nudges you or a teammate during game play, play up that contact and overly dramatize it. If the referee is as incompetent as you believe, he may fall for it and make a call in your favor. Be careful to not overuse this tactic, as other referees on the court may pick up on it and start penalizing your team as a result.
While you are limited in what you can do during a game to curtail a bad referee, you do have the right to file a formal complaint after the game is over. Nearly every organized basketball league, even on an intramural level, has standards and policies that their officials are expected to live up to. Videotape your games and then include the video of the game in question when complaining about any bad calls. Fill out any forms required by the sanctioning body and write a formal report explaining what calls were made by the referee and why those calls were faulty. Even if the referee isn't removed from duty, he may be prevented from refereeing your future games.