Your question looks like two questions in one. I'll deal with both separately. Do note they are both horribly difficult and complex questions that separate great players from good ones, and it's not realistic to discuss them in detail. For real help with whatever format you're playing, you should probably look for guides for the format you're playing, or even the specific deck.
Question one: how do you build a sideboard?
Use the Elephant method.
Writing out ideal realistic lists for all matchups and then trying to make the unique cards in those lists add up to 75 cards before deciding on the specific 60 for the maindeck and the specific fifteen for the sideboard
The linked article goes through a detailed case study. As you can see, it's not easy, and you really need to be familiar with the metagame to even begin.
Question two: how do you sideboard once you're in a match?
This strongly depends on both your and your opponent's decks. There are still general considerations however. Here are three articles by a Hall of Famer dealing with sideboarding for all the three macro archetypes in the game: aggro, control, and combo.
Briefly, in aggro vs. aggro you try to raise your curve slightly so that if the game goes long enough, you win. In aggro vs. control, you take out your interactive cards for more diverse threats that won't be swept away by whatever answers your opponents have. In aggro vs. combo, you want hate cards for the combo, but you can work with "soft hate" because your naturally fast clock will reduce the amount of time they have to work around your hate.
Briefly, in control vs. aggro, you add cheap answers to avoid getting run over and rely on your naturally stronger late-game to win once you establish control. In control vs. control, you go for a bomb spell that wins the game if it resolves (or possibly even if it's cast), or you can play threats that naturally generate value. In control vs. combo, you are very slow so your opponents will be able to beat "soft hate". You need targeted hate that wins the game if it resolves (and/or stays in play).
Briefly, there are two basic approaches: either you sideboard to beat their sideboard, or you transform. In the first approach you bring in cards that beat your opponent's hate cards, with the hope that if your opponent doesn't draw their sideboard cards then you win (i.e. your combo is so good that you win even if you draw your now-useless anti-hate cards), and if you both don't draw your sideboard cards then you win also. In the second approach, you bring in cards that function even if your opponent's hate cards are in play.