Yes. Community College is accepted. A full two years of my education is from one and I transferred them to the state college and in their eyes the credits are full and equal.
The only time you have to be cautious is when the course is online. First, check with the optometry school to see if online credits are accepted. But even if not, they won't know the difference if it doesn't indicate on your transcript whether the course was online or live. Check with the school registrar office to determine that.
The reason I know is I've looked into switching careers. A lot of graduate programs in the health field require you to retake the basic sciences if you took them more than five years prior. Those credits can be from a university or community college. No difference. Same goes for medical school.
In fact, there's an ONLINE General Microbiology course offered here from Colorado State University:
Courses - Pre-med Post-bacc Online Courses | CSU Online
Again, it might not even show on your transcript as online and even if it did, it probably doesn't matter. Now, with regard to the Microbiology Lab ... they don't offer that online and that's where you might be better picking up the credits from a community college.