Formal Brauer groups arising from certain weighted K3 surfaces Cohomology of Drinfeld modular varieties. Part II: Automorphic forms, trace formulas and Langlands correspondence. With an appendix by Jean-Loup Waldspurger 