What happens to the mining reward if the blocks gets replaced? When a block is added to the blockchain, the miner gets rewarded. But what would happen to the mining reward if the network replaced the block's branch with another because the latter is longer? If it was legit then how would the miner reference to the block which generated his coin?

P.S. - I'm new to SE, so I really don't know much about it.
If the block doesn't end up in the main chain, the miner effectively doesn't get the reward.  Attempts to spend it will not be accepted as valid payment by others.

There is a "maturity" rule that rewards cannot be spent at all until 100 more blocks have been added to the chain following it.  This helps ensure that a miner doesn't spend coins from a reward which is later invalidated, thus leaving the recipients of those payments in the lurch.