This paper introduces an automatic way of performing 3D static and dynamic elastoplastic analyses in the framework of the scaled boundary finite element method (SBFEM), which only requires the boundary discretization and thus can provide high flexibility in automatic mesh generation. The input models in this paper are described by Standard Tessellation Language (STL) format due to its simplicity and popularity in computer-aided design. The automatic mesh generation from any input geometry is achieved by utilizing the octree decomposition algorithm and boundary trimming. An efficient approach for 2D static image-based elastoplastic analysis based on SBFEM is extended to 3D static and dynamic elastoplastic analyses in this present work. In this improved approach, the return mapping algorithm is only required to be performed at the scaling center of each subdomain in the yield zone. Constant elastoplastic constitutive matrix and internal stresses are used within each yielded subdomain as well. This will greatly simplify the implementation of elastoplastic formulation and reduce the costs involved in the elastoplastic analysis as the return mapping algorithm is computationally expensive. Meanwhile, stabilization matrix is also introduced in the elastoplastic stiffness matrix to eliminate the spurious modes. Numerical examples are presented in this paper to show the feasibility and accuracy of the proposed approach as well as its capability of modelling complex structures in practical applications.