As for the flag and keyword changes, yes, the IDLE
extension was designed just for this purpose. Please note that gmail does not report flag changes when in IDLE. The linked thread contains a workaround. GMail's behaivor is completely breaindead, of course.
As for other changes, the NOTIFY extension is what you are looking for, but its support among servers is rather scarce -- only Dovecot, AFAIK. If your favorite IMAP client library doesn't offer it already, you should ask their authors.