I know iframes are not good for SEO. But still, if one needs to use it, is there any way to optimize them?
Not really any specific ways, no. Just optimize the contents of the frame like you would any other page, and its probably a good idea to put a link on the page with the iframe (not the page inside) that links to the page inside the iframe, so SE's can easily get to the frame content.
I just optimize the meta-tags and put content before and after the iframe, especially before with hyperlinked anchor text. But don't make it to long, especially if the iframe is the main content, I try to keep at least part of it in the first fold of the page. Oh and I almost forgot, use a text headline (h1 tag)