Biodiesel production by the in-situ transesterification method can be advantageous in reducing process costs due to the elimination of the oil extraction step. Also, consecutive use of biomass pyrolysis process after the biodiesel production process can help make the biofuel production process more economical. In the present study, optimization of biodiesel production by the in-situ transesterification from linseed, a non-edible, and inexpensive seed, was performed. At the end of the biodiesel production process, the linseed residue from the in-situ transesterification process was converted into valuable products by a slow pyrolysis process. Experimental design and optimization of biodiesel production experiments were done by Design Expert 11 software; where the three parameters of linseed particle size (Mesh No.), solvent to solid ratio (SSR), and co-solvent to alcohol ratio (C-S/A) were examined as the main parameters of the experimental design. Finally, the software proposed optimal conditions in the linseed particle size range of 0.212-0.300 mm (Mesh No. Of 50-70), solvent to seed ratio of 9.14 ml/g, co-solvent to alcohol ratio of 0.52 ml/ml, catalyst concentration of 5% (oil-based), agitation rate of 800 rpm, reaction temperature of 55 degrees C, and reaction time of 180 min. By performing experiments under these conditions, the purity and yield of biodiesel were 96.80% and 95.98%, respectively. Eventually, at the linseed residue pyrolysis process (at 500 degrees C and N2 rate of 200 cm3 forward slash min), the biomass conversion was 79.64%, and the bio-oil, biochar, and biogas yields were obtained at 32.68%, 20.36%, and 46.96%, respectively.