I am going to post a rather simplistic answer just covering the basics.
There are cases (1) where adding a 「と」 is appropriate, (2) where adding a 「と」 is inappropriate, and (3) where only adding a 「に」, not a 「と」, is appropriate.
1) When an onomatopoeia functions adverbially to modify a verb, a 「と」 is often added. In very informal speech, on the contrary, it is often omitted.
「ワンワンと[犬]{いぬ}が[鳴]{な}いている。」 = "A dog is barking 'bowwow'."
「[女]{おんな}はトウキョウナゴヤをゴツンと[殴]{なぐ}り、[部屋]{へや}を[出]{で}ていった。」= "The woman clonked TokyoNagoya in the head and ran out of the room."
2) When an onomatopoeia is used with the verb 「する」, it is inappropriate to add a 「と」.
「ニコニコするなっ!ここは[陸軍]{りくぐん}だ!マクドナルドじゃねえぞっ!」 = "Don't be smiling! This is the Army, not McDonald's!"
「トウキョウナゴヤは[仕事]{しごと}もしないでブラブラしている。」 = "TokyoNagoya is bumming around all day."
3) When describing a change of state using an onomatopoeia, one would generally need to add a 「に」 instead of a 「と」.
「くたくたになるまで[歩]{ある}いた。」 = "I walked until I was pooped."
「きんきんに[冷]{ひ}やしたビールはうまい。」 = "Ice-cold beer tastes good."