This thesis examines the privacy preserving energy management issue, taking into account both energy generation units and responsive demand in the smart grids. Firstly, because of the inherent stochastic behavior of the distributed energy resources, an optimal energy management problem is studied. Distributed energy resources are used in the decentralization of energy systems. Large penetration of distributed energy resources without the precise cybersecurity measures, such as privacy, monitoring and trustworthy communication may jeopardize the energy system and cause outages, and reliability problem for consumers. Therefore, a blockchain based decentralized energy system to accelerate electrification by improving service delivery while minimizing the cost of generation and addressing historical antipathy and cybersecurity risk is proposed. A case study of sub-Sahara Africa is considered. Also, a blockchain based energy trading system is proposed, which includes price negotiation and incentive mechanisms to address the imbalance of order. Besides, the Internet of energy makes it possible to integrate distributed energy resources and consumers. However, as the number of users involved in energy transactions increases, some factors are restricting conventional centralized energy trading. These factors include lack of trust, privacy, fixed energy pricing, and demurrage fees dispute. Therefore, additive homomorphic encryption and consortium blockchain are explored in this thesis to provide privacy and trust. Additionally, a dynamic energy pricing model is formulated based on the load demand response ratio of prosumers to address the fixed energy pricing problem. The proposed dynamic pricing model includes demurrage fees, which is a monetary penalty imposed on a prosumer if it failed to deliver energy within the agreed duration. Also, a new threat model is designed and analyzed. Secondly, mobile prosumers, such as electric vehicles offer a wide range of sophisticated services that contribute to the robustness and energy efficiency of the power grid. As the number of vehicles in the smart grid grows, it potentially exposes vehicle owners to a range of location related privacy threats. For example, when making payments, the location of vehicles is typically revealed during the charging process. Also, fixed pricing policy and lack of trust may restrict energy trading between vehicles and charging stations. Therefore, a private blockchain system is proposed to preserve the privacy of vehicle owners from linking based attack while a public blockchain system is established to enhance energy trading. Various parameters are used to formulate a demand based pricing policy for vehicles, such as time of demand, types of vehicles and locations. Using the demand based pricing policy, an optimal scheduling method is designed to maximize the vehicles both social welfare and utility. An improved consensus energy management algorithm is proposed to protect the privacy of vehicle owners by applying differential privacy. The proposed system is robust against temporal and spatial location based privacy related attacks. Thirdly, blockchain is an evolving decentralized data collection technology, which costeffectively exploits residential homes to collate large amounts of data. The problems of blockchain are the inability to withstand malicious nodes, which provide misleading information that destabilize the entire network, lack of privacy for individual node and shared data inaccuracy. Therefore, a secure system for energy users to share their multi-data using the consortium blockchain is proposed. In this system, a credibility based Byzantine fault tolerance algorithm is employed as the blockchain consensus mechanism to achieve the fault tolerance of the system. Also, a recurrent neural network is used by certain honest users with credibility to forecast the energy usage of other honest users. A recurrent neural network operates on the collated data without revealing the private information about honest users and its gradient parameters. Moreover, additive homomorphic encryption is used in the recurrent neural network to secure the collated data and the gradient parameters of the network. Also, a credibility management system is proposed to prevent malicious users from attacking the system and it consists of two layers: upper and lower. The upper layer manages global credibility that reflects the overall readiness of honest users to engage in multi-data sharing. The lower layer performs local credibility that reflects certain feedback of honest users on the accuracy of the forecast data. Lastly, combining blockchain mining and application intensive tasks increases the computational cost for resource constrained energy users. Besides, the anonymity and privacy problems of the users are not completely addressed in the existing literature. Therefore, this thesis proposes an improved sparse neural network to optimize computation offloading cost for resource constrained energy users. Furthermore, a blockchain system based on garlic routing, known as GarliChain, is proposed to solve the problems of anonymity and privacy for energy users during energy trading in the smart grid. Furthermore, a trust method is proposed to enhance the credibility of nodes in the GarliChain network. Simulations evaluate the theoretical results and prove the effectiveness of the proposed solutions. From the simulation results, the performance of the proposed model and the least-cost option varies with the relative energy generation cost of centralized, decentralized and blockchain based decentralized system infrastructure. Case studies of Burkina Faso, Cote d’Ivoire, Gambia, Liberia, Mali, and Senegal illustrate situations that are more suitable for blockchain based decentralized system. For other sub-Sahara Africa countries, the blockchain based decentralized system can cost-effectively service a large population and regions. Additionally, the proposed blockchain based levelized cost of energy reduces energy costs by approximately 95% for battery and 75% for the solar modules. The future blockchain based levelized cost of energy varies across sub-Sahara Africa on an average of about 0.049 USD/kWh as compared to 0.15 USD/kWh of an existing system in the literature. The proposed model achieves low transaction cost, the minimum execution time for block creation, the transactional data privacy of prosumers and dispute resolution of demurrage fees. Moreover, the proposed system reduces the average system overhead cost up to 66.67% as compared to 33.43% for an existing scheme. Additionally, the proposed blockchain proof of authority consensus average hash power is minimized up to 82.75% as compared to 60.34% for proof of stake and 56.89% for proof of work consensus mechanisms. Simulations are also performed to evaluate the efficacy of the proposed demand based pricing policy for mobile prosumers. From the simulation results, the proposed demand based pricing policy is efficient in terms of both low energy price and average cost, high utility and social welfare maximization as compared to existing schemes in the literature. It means that about 89.23% energy price reduction is achieved for the proposed demand based pricing policy as compared to 83.46% for multi-parameter pricing scheme, 73.86% for fixed pricing scheme and 53.07% for the time of use pricing scheme. The vehicles minimize their operating costs up to 81.46% for the proposed demand based pricing policy as compared to 80.48% for multi-parameter pricing scheme, 69.75% for fixed pricing scheme and 68.29% for the time of use pricing scheme. Also, the proposed system outperforms an existing work, known as blockchain based secure incentive scheme in terms of low energy prices and high utility. Furthermore, the proposed system achieves an average block transaction cost of 1.66 USD. Besides, after applying the differential privacy, the risk of privacy loss is minimum as compared to existing schemes. Furthermore, higher privacy protection of vehicles is attained with a lower information loss against multiple background knowledge of an attacker. To analyze the efficiency of the proposed system regarding multi-data sharing, an experimental assessment reveals that about 85% of honest users share their data with stringent privacy measures. The remaining 15% share their data without stringent privacy measures. Moreover, the proposed system operates at a low operating cost while the credibility management system is used to detect malicious users in the system. Security analysis shows that the proposed system is robust against 51% attack, transaction hacking attack, impersonation attack and the double spending attack. To evaluate the proposed system regarding energy management of resource constrained blockchain energy users, a Jaya optimization algorithm is used to accelerate the error convergence rate while reducing the number of connections between different layers of the neurons for the proposed improved sparse neural network. Furthermore, the security of the users is ensured using blockchain technology while security analysis shows that the system is robust against the Sybil attack. Moreover, the probability of a successful Sybil attack is zero as the number of attackers’ identities and computational capacities increases. Under different sizes of data to be uploaded, the proposed improved sparse neural network scheme has the least average computational cost and data transmission time as compared to deep reinforcement learning combined with genetic algorithm, and sparse evolutionary training and multi-layer perceptron schemes in the literature. Simulation results of the proposed GarliChain system show that the system remains stable as the number of path requests increases. Also, the proposed trust method is 50.56% efficient in detecting dishonest behavior of nodes in the network as compared to 49.20% of an existing fuzzy trust model. Under different sizes of the blocks, the computational cost of the forwarding nodes is minimum. Security analysis shows that the system is robust against both passive and active attacks. Malicious nodes are detected using the path selection model. Moreover, a comparative study of the proposed system with existing systems in the literature is provided.