Do I have to make someone coauthor if he/she solves a problem in StackExchange, asked by myself, which is later used in my paper?
I have been in this precise situation. I wrote the manuscript to a reasonably finished state and then contacted the helpful SE person, asking if they want to be a coauthor and whether the attribution is sufficient. The attribution consisted of citing the MO answer and additionally naming them in the acknowledgements.

This approach has the benefit of maintaining or building a good relationship with the helpful person.

Remember that the typical norms of co-authorship include intellectual contribution, as well as writing or critical review of the manuscript, and in any case accepting the final paper. If you see their contribution as relatively minor, you might want to offer them the possibility to extend or otherwise improve the paper if they are interested in co-authorship.

If the contribution does not merit co-authorship, you can still cite it or acknowledge the (possibly anonymous) contributor on SE, if that is warranted. It is polite, but not required, to ask the person how they should be referred to, in any case.