Consistent boundary conditions for Alexandrov-Kontsevich-Schwartz-Zaboronsky (AKSZ) sigma models and the corresponding boundary theories are analyzed. As their mathematical structures, we introduce a generalization of differential graded symplectic manifolds, called twisted QP manifolds, in terms of graded symplectic geometry, canonical functions, and QP pairs. We generalize the AKSZ construction of topological sigma models to sigma models with Wess-Zumino terms and show that all the twisted Poisson-like structures known in the literature can actually be naturally realized as boundary conditions for AKSZ sigma models