Can I get married while on STEM extension EAD?
In the states I'm familiar with, yes. As far as I know, no US state requires you to be in any particular immigration status to get married.
Will my spouse be able to get an F-2 visa considering my current visa being close to expiration?
The expiration of your visa is not relevant. The expiration of the period of admission reflected on your I-94 form might be relevant, but I do not see any indication that it in fact is relevant. See the Foreign Affairs Manual at 9 FAM 402.5.
Would the EAD validity be considered in this case or it's solely dependent on the F1 visa date?
The expiration of your EAD is also not particularly relevant. The EAD does not permit you to be in the United States; it only permits you to work in the United States. You should be careful to maintain valid immigration status as reflected on your I-94 form. You have probably been admitted for "D/S," meaning "duration of status"; in that case, you can remain in the US as long as you fulfill the requirements of F-1 status. If your employment ends early, therefore, you cannot rely on the EAD alone to remain in the US.
I would also note that once you are married, if your spouse is in the United States, she cannot get an F-2 visa. She can either leave the country to apply for a visa or apply to change her nonimmigrant status. If she changes into F-2 status without leaving the country, but subsequently leaves the country and wishes to return (except for trips shorter than 30 days to Canada or Mexico), she will need to get an F-2 visa while she is outside the US.