Attributing contributions to academic work that occur in Stack Exchange Sometimes we may ask questions on stack exchange or online forums wherein the response is helpful or even essential to a piece of work that gets published in an academic journal. If this occurs, how should credit be given to those involved in the exchange? Should they all be included as authors? Should a link to the forum be included as a reference in the paper?

Once something is in a stack exchange or forum, it's "published". Perhaps in the future, the current peer review model will transform into people writing blogs and posting in forums and databases. But for now, how might this issue be dealt with while forums, blogs, etc coexist with journals?
Issue of citing authorship
Starting from first principles, I think in most instances on StackExchange it would be the original poster of the quoted answer that would be the relevant author. The person asking the question is useful but it is typically the information provided in a particular answer that would be the typical candidate for citation.
That said, I imagine there could be instances where the question itself or an overall exchange represents the unit of citation. In such a case, it would make sense to cite all relevant contributors.
Does something learnt from StackExchange need to be cited?
A lot of learning goes into a journal article. This learning comes from many sources. That which gets cited is only a small fraction of that. A scientist might (a) read a statistics book; (b) ask a friend;  or (c) ask a question on Stats.StackExchange.com to learn more about how to analyse his or her data. In both cases, the person has devised an analysis plan based on having learnt something. However, generally these sources are not cited. In each case the scientist has learnt how to do something, but ultimately the knowledge is already established in the literature.
I also think that the vast majority of posts on StackExchange do not constitute a citable unit of original research. That said, where this does occur and it it influences your work, it makes sense to cite the source.