"Beer can be clairified using Irish moss, a fining agent. Fining agents all work by making the smaller molecules aggregate into larger particles so they settle out of solution. This can be mathematically described by Stokes Law:
Where v is the rate of sedimentation, r1 is the density of the particle and r2 is the density of the wort, r is the radius of the particle, g is 9.8 m/sec2 (a.k.a. acceleration due to gravity), and h is the viscosity of the medium. In other words, as the density and size of the particle increases it will settle out faster. In addition, a thinner wort will allow settling to occur faster.
Irish moss is Atlantic red seaweed[2] that contains k-carrageenan:
The k-carrageenan is a polymer of β-D-galactose-4-sulphate-3,6-anhydro-a-D-galactose. It is similar to starch or cellulose (i.e. comprised of thousands of carbohydrates). The negatively charged sulfate groups are thought to interact with the proteins in suspension. As the wort cools, more and more proteins interact with the k-carrageenan and the k-carrageenan adopts a more compact structure. The result is the molecular equivalent of marbles in syrup. After the churning of an active fermentation ends (4-5 days) the carrageenan-protein chunks settle out with the yeast.
Homebrewed beer is still often cloudy, but Irish moss does make a noticable difference."
http://homebrewandchemistry.blogspot.com/2009/01/irish-moss-brief-description.html
Basically, you add it at the last 15-20 minutes of the boil and it makes the proteins fall out of the beer giving you a clearer product. Another thing to note is that Irish Moss is the same thing as Whirlfloc which is ground up Irish Moss that comes in little tablets. I personally think Whirlfloc is a little bit more convenient. I have never brewed without using whirlfloc.
As for the trub, the easiest way to get rid of it is just to let it settle out and rack your beer off the top into your bottling bucket or keg. Some people do a whirlpool so that very little trub makes it into the fermenter in the first place but that is a bit trickier.
https://www.homebrewtalk.com/f39/dealing-trub-221815/