If the question you post to math.stackexchange involves your personal education, and specifically you are seeking help to overcome an error you are encountering applying a specific method to a specific problem, then there is no need to acknowledge or give attribution.
If, instead, you post questions that are directly related to your research question and essential to your research progress, then you have an ethical obligation to provide notice and attribution in the body of your published research. This could be done in footnotes/endnotes associated with those specific steps, or in an Acknowledgements section. For example, in a footnote you might say:
"This solution [formulation/approximation/step...] comes from 'ysk', a member of the math.stackexchange online community, in response to my posted question (https://math.stackexchange.com/myquestion/answered). I am grateful for his/her assistance."
EDIT: added URL to footnote. However, since some communities are not publicly available and those that are may not have permanent URLs for posts, this may or may not be appropriate for published academic articles.
While some people might consider this to be ethical "overkill", I believe that it is better to err in the direction of giving more credit to others rather than less. Anything that appears in our paper that is not yours originally deserves to be credited to the original author. Mostly this is done through citations, but there are times when other methods are needed.