Thank you for your question and welcome to the Wefugees Community!
Here is an article from the Weefugees blog, which might contain interesting information for you (scroll down for English).
In principe, your boyfriend and you can marry, after which he will qualify for a residence and work permit (§5 Abs. 1 FreizügigG/EU).
Depending on the papers, which he holds, this might however be a complicated process. For instance, you need to submit following documents:
- a valid passport, ID or certificate of citizenship : if your boyfriend holds one and submitted it to BAMF, he should be able to get a certified copy. If he only has a Tazkira, or does not hold any identity papers from Afghanistan, I recommend you to contact a local legal aid group as he will have to try and get a passport, which, in principle, is possible - but pretty tricky.
- a birth certificate (the Tazkira is sufficient)
- and (in some cases) a certificate of no impediment from his country of origin; since it is not common in most countries, including Afghanistan, the Standesamt can make exceptions (so called "Befreiung von der Beibringung des ausländischen Ehefähigkeitszeugnis" - § 1309 Abs. 2 BGB).
I recommend you to get in touch with the Standesamt of the city where you or your boyfriend live as soon as possible to be sure to gather all the necessary documents (they might ask for more than the 3 I just cited, and the process for the exemption of certificate of no impediment can be quite long).
Furthermore, since his asylum claim was rejected, the Ausländerbehörde might suspect you to marry for the only purpose of getting a residence permit (fictious marriage or "Scheinehe"). In such cases, they investigate to make sure this is not the case. Be prepared to cooperate in order to avoid any inconvenience.
Finally, again, it is important to act fast since the fact to plan the wedding won't prevent a deportation in the case your boyfriend's appeal gets rejected (this will only be the case after you submit all documents and your wedding application has been approved).
I hope this answer and the blog article are helpful! Don't hesitate to add a comment if you need additional information.
All the best,