The question basically says it all. I am in the midst of writing a thermodynamics textbook, and there is a question I would like to answer that could be answered by pretty much just copying and pasting the relevant sections of the book. Is this a bad idea? Is it considered copyright infringement if I post here first and then later on include the same text in the published book? If it's not a problem, would I need to include copyright information in the book that references my answer and Physics.SE and such?
First, the obligatory disclaimer that I'm not a lawyer, this is not legal advice, etc. For a commercial project like a textbook (well, if you're planning to sell it), you should probably get a real legal opinion.
That being said, I think this is a pretty clear case under US law: with one possible exception that I can think of, posting something here has no effect on your ability to put that same content in a textbook you write, or to syndicate it to a blog, post it on social media, or so on. This is because, when you post content on a Stack Exchange site, you retain ownership of the copyright on that content, and the license you grant to SE to distribute it is nonexclusive. As the copyright owner, you can continue to copy, distribute, transform, etc. that content in absolutely any way you want. You can also give other people permission to do the same.
The fact that SE receives the content under a particular Creative Commons license is ultimately irrelevant. That only affects what Stack Exchange is allowed to do with your content, and what people who get your content from Stack Exchange can do with it. It doesn't affect what you, as the copyright owner, can do with it.
The one exception I mentioned is this: if you are using a commercial publisher for your textbook, they may require that the content you submit to them has not been distributed elsewhere, and they may additionally require that you grant them an exclusive license to distribute that content. Exclusive, of course, means that they will be the only ones allowed to redistribute it. If you have already submitted the content to Stack Exchange, then obviously it has been distributed, and you can't give your publisher an exclusive license to distribute it. So you will have to either negotiate some different terms with them, or find a different publisher. And if you submit content to your publisher and give them an exclusive license to distribute it, you can certainly no longer submit it to SE - at least not as a verbatim copy. (Unless it falls under the fair use exception, which could get complicated.)
But this exception is all just stuff that your publisher might include in the legal agreements you sign with them. It's not part of copyright law itself.