The task of comparing regression slopes is very common in practice. However, the sample size needed for the task suffers from a lack of statistical power and the heterogeneous variance problem. Furthermore, considering the different costs for each group and the need to allocate a different sample size for each group for optimization purposes, the present study aims to provide innovative solutions for calculating the optimal sample sizes by using two tests. The first is for testing the equality of slopes and constructing CIs simultaneously. The second is for testing the equivalence of slopes. An exhaustive local search algorithm for maximal statistical power or minimal sampling cost is provided. The proposed method incorporates profound factors such as unequal error variances, different sampling unit costs, and different variances of the predictor. The application of the method can therefore be comprehensive for both experimental and non-experimental studies. The proposed method is validated using a simulation to obtain the empirical Type I error rate and statistical power. Sample size tables, two R Shiny apps, and R codes are provided for easy use.