Why is it a good idea to fianchetto above the castled King? If I do that, should I make sure to leave the Bishop there for a while to guard the hole? I understand why fianchettoing can be helpful, even deadly to an opponent, but should it really be done on the side which the King castles into?  I realize that the King's Indian Defense/Attack involves fianchettoing on the kingside as well as castling to the kingside, for Black and White respectively; and that that position is quite strong.  But I'd like to know the principle behind opening up the N-pawn above the castled King.  Is it a weak point?  And if so, should I be careful not to move my Bishop from the fianchetto square?

I suppose more generally my question is: what should I be careful of when advancing a pawn in front of a castled King in the early to middle game?
Fianchettoes are a very common and strong setup. But watch also for the 2 most common attacks against a fianchettoed position, which are:

A. Launching the rook pawn up the board (against Black this would be h4-h5 etc.) and opening up the h-file. I have played this many times against the Pirc where Black "castles into" the attack. White plays h4-h5 followed by trading off the pawn and then plays Qh6+ with a very strong attack down the open file. 

B. The sacrifice of a knight on f5 (where Black accepting the sac would play ...gxf5). This wrenches open the position and jacks up the pawn structure. 

Even if the opponent trades his same-color bishop for your fianchettoed bishop, you can still become weak on that color complex (e.g. the opponent's queen can roost on h6 for example and be a thorn in your side)